<?php

/**
 * Resources form.
 *
 * @package    rms
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class ResourcesForm extends BaseResourcesForm
{
  public function configure()
  {

    $this->useFields( array( 'code', 'category', 'name', 'description', 'position', 'state' ));

    $this->widgetSchema->setLabels(array(
      'code'  => 'Código',
      'category' => 'Categoría',
      'name' => 'Nombre',
      'description' => 'Descripción',
      'position' => 'Posicion',
      'state' => 'Estado',
    ));
    $this->embedRelation('ResourcesPictures');
//       $picture = new ResourcesPictures();
//       $picture->Resources = $this->getObject();
//       $form = new ResourcesPicturesForm( $picture );
//       $this->embedForm('', $form );
    
//     $attr = $this->getObject()->getResourcesAttributesData();
//     if ( !$attr )
//     {
//       $picture = new Picture();
//       $picture->setCard($this->getObject());
//       $pictures = array($picture);
//     }
// 
//     //An empty form will act as a container for all the pictures
//     $pictures_forms = new SfForm();
//     $count = 0;
//     foreach ($pictures as $picture) {
//       $pic_form = new PictureForm($picture);
//       //Embedding each form in the container
//       $pictures_forms->embedForm($count, $pic_form);
//       $count ++;
//     }
//     //Embedding the container in the main form
//     $this->embedForm('pictures', $pictures_forms);
  }

  public function addPicture()
  {
    sfContext::getInstance()->getLogger()->info('FORMMMMMMMMM click');
    $picture = new ResourcesPictures();
    $picture->setResource($this->getObject());
    $picture_form = new ResourcesPicturesForm($picture);

    $this->embedForm( 'new', $picture_form );
  }

  public function bind( array $taintedValues = null, array $taintedFiles = null ){

//     $new_occurrences = new BaseForm();
//     foreach($taintedValues['new'] as $key => $new_occurrence){
// 
//       $picture = new ResourcesPictures();
//       $picture->setResource($this->getObject());
//       $picture_form = new ResourcesPicturesForm($picture);
// 
//       $new_occurrences->embedForm($key,$picture_form);
//     }
//  sfContext::getInstance()->getLogger()->info('x click x');
//     $this->embedForm('new',$new_occurrences);
//  sfContext::getInstance()->getLogger()->info('x click');
//     parent::bind($taintedValues, $taintedFiles);
  }

}
